package com.xingyun.info_manager.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.xingyun.info_manager.dao.ReportNetDao;
import com.xingyun.info_manager.entity.AdminUser;
import com.xingyun.info_manager.entity.ParasBean;
import com.xingyun.info_manager.entity.PriAccountInfo;
import com.xingyun.info_manager.entity.ReturnBeans;
import com.xingyun.info_manager.service.IReportNetService;
import com.xingyun.info_manager.util.JSONChange;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Classname ReportNetController
 * @Description 数据统计报表（网络）
 * @Date 2020/6/1 15:48
 * @Created by You
 */
@Controller
public class ReportNetController {

    @Autowired
    private IReportNetService reportNetService;


    /**
     * 获取报表基本信息
     * @return
     */
    @ResponseBody
    @RequestMapping("/repnet/getinfo")
    public String getPriAccountInfo(HttpServletRequest request) throws JsonProcessingException {
        String userName = request.getParameter("userName");//登录用户
        String appointDept = request.getParameter("appointDept");//科室
        String diseaseEntities = request.getParameter("diseaseEntities");//病种

        //用于传参实体类
        ParasBean parasBean = new ParasBean();
        parasBean.setUserName(userName);
        parasBean.setAppointDept(appointDept);
        parasBean.setDiseaseEntities(diseaseEntities);

        Integer currPage;//当前页数
        if(!StringUtils.isBlank(request.getParameter("currPage"))) {
            currPage = Integer.valueOf(request.getParameter("currPage"));
        } else {
            currPage = 1;
        }
        parasBean.setCurrPage(currPage);

        Integer pageSize;//每页展示条数
        if(!StringUtils.isBlank(request.getParameter("pageSize"))) {
            pageSize = Integer.valueOf(request.getParameter("pageSize"));
        } else {
            pageSize = 5;
        }
        parasBean.setPageSize(pageSize);
        //返回的响应对象
        ReturnBeans<List<PriAccountInfo>> returnBean = new ReturnBeans<List<PriAccountInfo>>();
        returnBean.setCurrPage(currPage);
        returnBean.setPageSize(pageSize);
        //根据页数和显示条数计算分页起始位置
        int initPage = (currPage - 1) * pageSize;
        parasBean.setInitPage(initPage);

        /**
         * 查询总条数
         */
        int count = reportNetService.findCount(parasBean);
        returnBean.setCount(count);
        System.out.println("------ "+initPage+","+pageSize+","+count);

        /**
         * 查询详细信息
         */
        List<PriAccountInfo> adminList =  reportNetService.getPriAccountInfo(parasBean);
//        request.setAttribute("adminList",adminList);
        returnBean.setData(adminList);
        request.setAttribute("page",returnBean);
        System.out.println(" - --" + JSONChange.objToJson(returnBean));
        //将对象转为json字符串返回
        return JSONChange.objToJson(returnBean);
    }


    /**
     * 获取图形报表基本信息（当天录入量、当天到院量）
     * @return
     */
    @ResponseBody
    @RequestMapping("/repnet/todayinfo")
    public String getTodayInfo(HttpServletRequest request) throws JsonProcessingException {
        //返回的响应对象
        ReturnBeans<PriAccountInfo> returnBean = new ReturnBeans<PriAccountInfo>();

        /**
         * 查询详细信息
         */
        PriAccountInfo priAccount =  reportNetService.getTodayInfo();
//        request.setAttribute("adminList",adminList);
        returnBean.setData(priAccount);
        System.out.println(" - --" + JSONChange.objToJson(returnBean));
        //将对象转为json字符串返回
        return JSONChange.objToJson(returnBean);
    }

}
